package com.fashionbrot.github.util;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.math.BigDecimal;

public class BigDecimalFormat extends JsonSerializer<BigDecimal> {


    @Override
    public void serialize(BigDecimal aDouble, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {

        if(aDouble != null) {
            jsonGenerator.writeNumber(DecimalFormatUtil.convert(aDouble));
        }else{
            jsonGenerator.writeNumber(0);
        }
    }
}
